package com.lc.hot100.lc2;

import com.lc.utils.ListNode;

public class Main {

}

class Solution {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode head = new ListNode(0);
        ListNode t = head;
        int num = 0;
        while(l1 != null || l2 != null) {
        	
        	if (l1 != null) {
        		num += l1.val;
        		l1 = l1.next;
        	}
        	if (l2 != null) {
        		num += l2.val;
        		l2 = l2.next;
        	}
        	
        	t.next = new ListNode(num % 10);
        	t = t.next;
        	num = num / 10;
        	if (l1 == null && l2 == null && num != 0) {
            	t.next = new ListNode(num % 10);
            	t = t.next;
            	num = num / 10;
        	}
        }
        return head.next;
        
    }
}
